#include <stdio.h>
#include "stdlib.h"
#include "time.h"
typedef char ElementType;
typedef struct LNode *List;
struct LNode{
    ElementType data;
    List next;
    List prev;
};
//初始化链表(带头)
List listInit(){
    List c;
    c = (List) malloc(sizeof (struct LNode));
    c->next = NULL;
    c->prev = NULL;
    return c;
}
//尾插法
void addLast(List Ptr,ElementType x) {
    List s,c;
    c = Ptr;
    s = (List) malloc(sizeof (struct LNode));
    s->data = x;
    s->next = NULL;
    while(c->next!=NULL) {
        c = c->next;
    }
    s->prev = c;
    c->next = s;
    return;
}
//生成L1
void createL1(List Ptr) {
    Ptr->data = '9';
    srand((unsigned ) time(NULL));
    List cur;
    cur = Ptr;


    //随机生成符号
    int x;
    for (int i = 1; i <= 9; ++i) {
        switch (i%3) {

            case 0:
                x = 33 + rand()%15;
                addLast(cur,x);
                break;
            case 1:
                x = 65 + rand()%26;
                addLast(cur,x);
                break;
            case 2:

                x = 48 + rand()%10;
                addLast(cur,x);
                break;
            default:
        }
    }
}
//生成L2
void createL2(List L2,List L1) {
    L2->data = '3';
    List cur = L1 ->next;
    List s ,p;
    p = L2;

    while(cur) {
        if(cur->data >= 'A' && cur->data <= 'Z' ) {
            s = (List) malloc(sizeof (struct LNode));
            s->next = NULL;
            s->data = cur->data;
            p->next = s;
            s->prev = p;
            p = p->next;
            List a = cur;
            a->prev->next = a->next;
            a->next->prev = a->prev;

        }
        cur = cur->next;
    }
    return;
}
//生成L3
void createL3(List L3,List L1) {
    L3->data = '3';
    List cur = L1->next;
    List s ,p;
    p = L3;
    while(cur) {
        if(cur->data >= '0' && cur->data <= '9' ) {
            s = (List) malloc(sizeof (struct LNode));
            s->next = NULL;
            s->data = cur->data;
            p->next = s;
            s->prev = p;
            p = p->next;
            List a = cur;
            a->prev->next = a->next;
            a->next->prev = a->prev;
        }
        cur = cur->next;
    }

    return;
}

int main() {
    List L1,L2,L3;
    L3 = listInit();
    L2 = listInit();
    L1 = listInit();

//L1
    createL1(L1);
    List cur1 = L1;
    while(cur1) {
        printf(" %c ",cur1->data);
        cur1 = cur1->next;
    }
    printf("\n");
//L2
    createL2(L2,L1);
    List cur2 = L2;
    while(cur2) {
        printf(" %c ",cur2->data);
        cur2 = cur2->next;
    }
    printf("\n");

    //L3
    createL3(L3,L1);
    List cur3 = L3;
    while(cur3) {
        printf(" %c ",cur3->data);
        cur3 = cur3->next;
    }

//最后的L1
    printf("\n");
    List cur11 = L1;
    cur11->data = '3';
    while(cur11) {
        printf(" %c ",cur11->data);
        cur11 = cur11->next;
    }
    //释放L1 L2 L3
    free(L1);
    free(L2);
    free(L3);


    return 0;
}
